package com.sg.service.biz.component.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.component.req.ImplementSingleMultipleFieldSetDataEntryComReqDto;
import com.sg.dto.biz.component.req.ImplementSingleMultipleFieldSetDataEntryReqDto;
import com.sg.dto.biz.component.req.ImplementSingleSetDataEntryComReqDto;
import com.sg.dto.biz.component.req.ImplementSingleSetDataEntryReqDto;
import com.sg.dto.biz.component.res.ImplementSingleMultipleFieldSetDataEntryComRespDto;
import com.sg.dto.biz.component.res.ImplementSingleMultipleFieldSetDataEntryRespDto;
import com.sg.dto.biz.component.res.ImplementSingleSetDataEntryComRespDto;
import com.sg.dto.biz.component.res.ImplementSingleSetDataEntryRespDto;
import com.sg.service.base.component.MCustomFields3Service;
import com.sg.common.exception.Assert;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class DataSetSingleEntryServiceImpl
        implements com.wicket.okrcomponent.biz.service.DataSetSingleEntryService {

    @Resource
    private RedisUtil redisUtil;
    //@Resource
    //private MCustomFields2Service mCustomFields2Service;
    @Resource
    private NbDataSetSingleEntry nbDataSetSingleEntry;
    @Resource
    private MCustomFields3Service mCustomFields3Service;

    /**
     * D2执行单条转数据集(公共)[9603]
     * gen by moon at 5/18/2024, 7:24:06 PM
     */
    @Trace(operationName = "D2执行单条转数据集(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ImplementSingleSetDataEntryComRespDto implementSingleSetDataEntryCom(ImplementSingleSetDataEntryComReqDto reqDto) {


        ImplementSingleSetDataEntryRespDto objectToDataRes_1 = null;
//步骤0: M2执行单条转数据集 - implementSingleSetDataEntry
        //ModelCode: objectToData
        ImplementSingleSetDataEntryRespDto objectToDataRes = null;
        ImplementSingleSetDataEntryReqDto objectToDataReq = new ImplementSingleSetDataEntryReqDto();
        if (reqDto != null) {
            objectToDataReq.setDatasetField(reqDto.getDatasetField());//SimpleFieldAssign//sourceId:1807158_1
        }

        /*M2执行单条转数据集[9602]  用于周期阶段资料内容中查询的多个图片信息，数据库中一个字段中的信息将转换到多张图片信息的地址（数据集）供前端展示 */

        objectToDataRes = nbDataSetSingleEntry.implementSingleSetDataEntry(objectToDataReq);


        objectToDataRes_1 = objectToDataRes;

        ImplementSingleSetDataEntryComRespDto retData = new ImplementSingleSetDataEntryComRespDto();
        if (objectToDataRes_1 != null) {
            retData.setSingleSetDataEntryList(objectToDataRes_1.getSingleSetDataEntryList());//list-field-assign//sourceId:1807162_1
        }


        return retData;
    }

    /**
     * D2执行单条多字段转数据集(公共)[9762]
     * gen by moon at 12/8/2024, 3:21:37 AM
     */
    @Trace(operationName = "D2执行单条多字段转数据集(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ImplementSingleMultipleFieldSetDataEntryComRespDto implementSingleMultipleFieldSetDataEntryCom(ImplementSingleMultipleFieldSetDataEntryComReqDto reqDto) {


        ImplementSingleMultipleFieldSetDataEntryRespDto objectToDataRes_1 = null;
//步骤0: M2执行单条多字段转数据集（特殊方法） - implementSingleMultipleFieldSetDataEntry
        //ModelCode: objectToData
        ImplementSingleMultipleFieldSetDataEntryRespDto objectToDataRes = null;
        ImplementSingleMultipleFieldSetDataEntryReqDto objectToDataReq = new ImplementSingleMultipleFieldSetDataEntryReqDto();
        if (reqDto != null) {
            objectToDataReq.setCustomField1(reqDto.getCustomField1());//SimpleFieldAssign//sourceId:1856401_1
            objectToDataReq.setCustomField2(reqDto.getCustomField2());//SimpleFieldAssign//sourceId:1856402_1
            objectToDataReq.setCustomField3(reqDto.getCustomField3());//SimpleFieldAssign//sourceId:1856403_1
            objectToDataReq.setCustomField4(reqDto.getCustomField4());//SimpleFieldAssign//sourceId:1856404_1
            objectToDataReq.setCustomField5(reqDto.getCustomField5());//SimpleFieldAssign//sourceId:1856405_1
            objectToDataReq.setCustomField6(reqDto.getCustomField6());//SimpleFieldAssign//sourceId:1856406_1
            objectToDataReq.setCustomField7(reqDto.getCustomField7());//SimpleFieldAssign//sourceId:1956098_1
        }

        /*M2执行单条多字段转数据集（特殊方法）[9761]  用于周期阶段资料内容中查询的多个图片信息，数据库中一个字段中的信息将转换到多张图片信息的地址（数据集）供前端展示 */
        Assert.isNull(objectToDataReq.getCustomField1(), "D2执行单条多字段转数据集(公共)-M2执行单条多字段转数据集（特殊方法）-自定义字段1不能为空", false);
        Assert.isNull(objectToDataReq.getCustomField2(), "D2执行单条多字段转数据集(公共)-M2执行单条多字段转数据集（特殊方法）-自定义字段2不能为空", false);
        Assert.isNull(objectToDataReq.getCustomField3(), "D2执行单条多字段转数据集(公共)-M2执行单条多字段转数据集（特殊方法）-自定义字段3不能为空", false);
        objectToDataRes = nbDataSetSingleEntry.implementSingleMultipleFieldSetDataEntry(objectToDataReq);


        objectToDataRes_1 = objectToDataRes;

        ImplementSingleMultipleFieldSetDataEntryComRespDto retData = new ImplementSingleMultipleFieldSetDataEntryComRespDto();
        if (objectToDataRes_1 != null) {
            retData.setComDatasList(objectToDataRes_1.getComDatasList().stream().map(item -> BeanUtil.toBean(item, ComDatasDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:1856414_1
        }


        return retData;
    }
    //
}
